<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/6/9
  Time: 10:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>我的服务添加页面</title>
    <%--引入css文件--%>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
</head>
<body>
<form class="layui-form" >
        <div class="layui-form-item">
            <label class="layui-form-label">客户:</label>
            <div class="layui-input-inline">
                <%--<select name="customer_Id" lay-verify="required">
                    <option value="">请选择</option>
                    <option value="101">客户1</option>
                    <option value="102">客户2</option>
                    <option value="103">客户3</option>
                </select>--%>
                <select name="customer_Id" lay-verify="required">
                    <option value="">请选择</option>
                    <c:forEach items="${sessionScope.customers}" var="customer">
                        <option value="${customer.id}">${customer.name}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">服务主题</label>
            <div class="layui-input-inline">
                <input type="text" name="general" lay-verify="required" placeholder="请输入服务主题" autocomplete="off" class="layui-input">
            </div>
            <label class="layui-form-label">服务时间</label>
            <div class="layui-input-inline">
                <input type="text" name="create_Date" id="create_Date" lay-verify="date" placeholder="请选择时间" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">服务类型:</label>
            <div class="layui-input-inline">
                <select name="type"  lay-verify="required">
                    <option value="">请选择</option>
                    <option value="投诉">投诉</option>
                    <option value="咨询">咨询</option>
                    <option value="售后">售后</option>
                    <option value="售中">售中</option>
                    <option value="售前">售前</option>
                </select>
            </div>
            <label class="layui-form-label">紧急程度:</label>
            <div class="layui-input-inline">
                <select name="emergency"  lay-verify="required">
                    <option value="">请选择</option>
                    <option value="紧急">紧急</option>
                    <option value="非常紧急">非常紧急</option>
                    <option value="一般">一般</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系电话：</label>
            <div class="layui-input-inline">
                <input type="text" name="phone_Number" lay-verify="number" placeholder="请输入手机号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">服务内容：</label>
            <div class="layui-input-inline">
                <textarea id="request" name="request"></textarea>
            </div>
        </div>

    <input type="hidden" name="creator" value="301">
    <input type="hidden" name="status" value="已归档">

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">添加</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

</form>
<%--引入js文件--%>
<script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script>
    //layui引入特定模块,运用模块中方法
    layui.use(['layedit','layer','form','jquery','laydate'],function () {
        var layedit = layui.layedit;//layedit富文本对象
        var layer=layui.layer;//layer弹窗对象
        var form= layui.form;//form表单对象
        var $=layui.$;//jquery对象
        var laydate = layui.laydate;

        var index =layedit.build('request'); //建立编辑器

        //开启日期
        laydate.render({
            elem: '#create_Date'
        });


        //设置编辑器属性
        layedit.set({
            uploadImage: {//图片上传的接口
                url: '${pageContext.request.contextPath}/service/uploadImg' //接口url
                ,type: 'post' //默认post
            },
            height:200
        });

        //submit 框监听事件
        form.on("submit(add)",function (data) {
            //将内容同步到textarea
            layedit.sync(index);
            // 获取表单数据项
            console.log( $("form").serialize());
            //异步请求 新增
            $.post("${pageContext.request.contextPath}/service/add", $("form").serialize(), function (result) {
                if (result.code == 0) {
                    layer.msg("添加成功!");
                    //刷新父窗口的表格 父窗口对象
                    parent.layui.table.reload("test", {
                        page: {
                            curr: 1
                        }
                    });
                    //关闭本窗口
                    //当你在iframe页面关闭自身时
                    var index=parent.layer.getFrameIndex(window.name);//得到当前iframe层索引
                    parent.layer.close(index);//执行关闭
                }
            }, "json");
            return false;
        })
    });
</script>
</body>
</html>
